package com.rr.learningdemo.stream.service.impl;

import com.rr.learningdemo.pojo.Person;
import com.rr.learningdemo.stream.bindings.MyProcessor;
import com.rr.learningdemo.stream.service.ReceiveMessageService;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author zhuangcanrun
 * @Date 2021/06/15/17:30
 * @description
 **/

@Service
public class ReceiveMessageServiceImpl {

//    @StreamListener(Processor.INPUT)
//    @SendTo(MyProcessor.MY_QUEUE)
//    @Override
//    public String receiveMessageFromInput(String message) {
//        System.out.println("exchange1接收到消息：{" + message+"},并将消息发给exchange2");
//        return message;
//    }

//    @StreamListener(value = Processor.INPUT)
//    public void receiveMessageFromInput(String message, @Headers Map<String, Object> map,@Header("sourceData")Object sourceData) {
//        System.out.println(map.size());
////        map.forEach((k, v) -> System.out.println(k + ":" + v));
//        System.out.println("exchange1接收到消息：{" + message + "}");
//    }

//    @StreamListener(value = Processor.INPUT,condition = "headers['type']=='json'")
//    public void receivePersonFromInput(Person person) {
//        System.out.println("exchange1接收到消息：{" + person+"}");
//    }
//
//    @StreamListener(value = MyProcessor.MY_INPUT,condition = "headers['contentType']=='text/plain'")
//    public void receiveMessageFromMyInput(String message) {
//        System.out.println("exchange2接收到消息:{" + message + "}");
//    }

}
